var drawBoard = function(pieces){

    sectionSize = 100;
	var sections = Math.sqrt(pieces);
	var xy = sectionSize * sections+20;

	var surface = dojox.gfx.createSurface("board", xy, xy);
	var groupBoard = surface.createGroup();
	
	for (var i = 0; i < pieces; i++) {

		var fillColor = '#'+Math.floor(Math.random()*16777215).toString(16);
	
		var shape = groupBoard.createRect({x:0,y:0,width:sectionSize,height:sectionSize})
			//.moveTo(0,sectionSize)
			.setFill(fillColor);
			//.setAbsoluteMode(false)
		;
		
	}
	return surface;
};

var playTurns = function(state, whosTurn){

	var result = decideWhoWon(state);
	if (result < 3) return result;
	//decideSolution(state);
	//setAndPlaceMovees();
	playTurns(state, whosTurn); //problem with incrementing turns
	
};


var playMatch = function(environment, state, whoGoesFirst) {

	result = playTurns(state, whoGoesFirst);


	
	// 3 is a not a result or a draw so keep playing

	//recursive function goes here

/*
	var groupO = surface.createGroup();
	var groupX = surface.createGroup();

	groupO.createCircle({cx: 50, cy: 50, r: 35})
		.setStroke({color: "black", width: 8})
	;

	groupX.createRect	({x: 0, y: 45, width: 100, height: 10})
	.setFill("black")
	;
	
	groupX.createRect	({x: 45, y: 0, width: 10, height: 100})
	.setFill("black")
	;
	
	groupX.setTransform([dojox.gfx.matrix.translate(200,200),dojox.gfx.matrix.rotategAt(45,50,50)]);
*/

};

var getState = function() {
};

var playSlidingPuzzle = function(pieces) {

	//add+1 because extra space is required
	environment = drawBoard(pieces+1);

};